package com.example;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MyActivity extends Activity {

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button start = (Button) findViewById(R.id.startService);
        Button stop = (Button) findViewById(R.id.stopService);

        /**
         * Anyway that just only one MyService instance created no matter how many times startservice
         */
        start.setOnClickListener(new StartServiceListener());
        stop.setOnClickListener(new StopServiceListener());
    }

    class StartServiceListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {

            System.out.println("on start listener listener....");
            Intent intent = new Intent();
            intent.setClass(MyActivity.this, MyService.class);
            intent.putExtra("name", "jasic");

            startService(intent);
        }
    }

    class StopServiceListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(MyActivity.this, MyService.class);
            stopService(intent);
        }
    }
}
